package com.cc.controller;


import com.cc.pojo.CLazz;
import com.cc.pojo.EmpQueryParam;
import com.cc.pojo.PageResult;
import com.cc.pojo.Result;
import com.cc.service.ClazzsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzsController {
    @Autowired
    private ClazzsService clazzsService;

    @GetMapping
    public Result list(EmpQueryParam empQueryParam){
        log.info("班级列表查询");
        PageResult<CLazz> pageResult =clazzsService.page(empQueryParam);
        return  Result.success(pageResult);

    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级");
        clazzsService.delect(id);
        return  Result.success();
    }


    @PostMapping
    public Result add(@RequestBody CLazz clazz){
        log.info("添加班级 {} "+ clazz);
        clazzsService.add(clazz);
        return  Result.success();
    }

    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        log.info("查询班级");
        CLazz clazz = clazzsService.getID(id);
        return Result.success(clazz);
    }
    @PutMapping
    public Result update(@RequestBody CLazz clazz){
        log.info("修改班级");
        clazzsService.update(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result find(){
        log.info("查询所有班级");
        List<CLazz> clazzList=clazzsService.findAll();
        return Result.success(clazzList);
    }
}
